package com.capinfo.service.impl;

import com.capinfo.base.BaseEntity;
import com.capinfo.base.BaseMapper;
import com.capinfo.base.impl.BaseServiceImpl;
import com.capinfo.entity.CapServiceDocument;
import com.capinfo.mapper.CapServiceDocumentMapper;
import com.capinfo.service.CapServiceDocumentService;
import com.capinfo.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: sunbenjin
 * @date: 2020/3/3
 **/
@Service
public class CapServiceDocumentServiceImpl extends BaseServiceImpl<CapServiceDocument,String> implements CapServiceDocumentService {

    @Autowired
    CapServiceDocumentMapper capServiceDocumentMapper;
    @Override
    public BaseMapper<CapServiceDocument, String> getMappser() {
        return capServiceDocumentMapper;
    }

    @Override
    public List<CapServiceDocument> selectListByPage(CapServiceDocument record) {
        return capServiceDocumentMapper.selectListByPage(record);
    }

    @Override
    public int insert(CapServiceDocument capServiceDocument) {
        capServiceDocument = super.addValue(capServiceDocument,false);
        return capServiceDocumentMapper.insert(capServiceDocument);
    }

    @Override
    public CapServiceDocument selectByPrimaryKey(Object o){
        return capServiceDocumentMapper.selectByPrimaryKey(o);
    }

    @Override
    public JsonUtil delById(String id, boolean flag) {
        JsonUtil j=new JsonUtil();

        try {
            CapServiceDocument capServiceDocument = selectByPrimaryKey(id);
            if (flag) {
                //逻辑
                capServiceDocument.setDelFlag(BaseEntity.DEL_FLAG_DELETE);
                updateByPrimaryKeySelective(capServiceDocument);
            } else {
                //物理
                capServiceDocument.setDelFlag(BaseEntity.DEL_FLAG_DELETE);
                updateByPrimaryKeySelective(capServiceDocument);
//                capServiceTypeMapper.delById(id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        j.setMsg("删除成功");
        return j;
    }

    @Override
    public void batchInsert(List<CapServiceDocument> list) {
        capServiceDocumentMapper.batchInsert(list);
    }

    @Override
    public void batchUpdate(List<CapServiceDocument> list) {
        capServiceDocumentMapper.batchUpdate(list);
    }


}
